package cn.com.dhcc.turbo.service.exch;

import java.io.File;

import cn.com.dhcc.app.core.handler.encrypthandler.EncryptFilter;
import cn.com.dhcc.app.pub.core.consts.AppConst.CrossNetType;
import cn.com.dhcc.app.pub.core.consts.AppConst.ExchDataType;
import cn.com.dhcc.app.pub.core.consts.KernelParam;
/**
 * 加密过滤器
 * @author qiao
 * @2015-2-5 @下午3:32:28
 */
public class TurboEncryptFilter<T> implements EncryptFilter<T>{

	private ExchDataType exchDataType;
	private CrossNetType crossNetType;
	private boolean dataCategoryEncryptEnabbled;
	public ExchDataType getExchDataType() {
		return exchDataType;
	}

	public CrossNetType getCrossNetType() {
		return crossNetType;
	}
    
	

	public boolean isDataCategoryEncryptEnabbled() {
		return dataCategoryEncryptEnabbled;
	}

	public TurboEncryptFilter(ExchDataType exchDataType,
			CrossNetType crossNetType, boolean dataCategoryEncryptEnabbled) {
		this.exchDataType = exchDataType;
		this.dataCategoryEncryptEnabbled = dataCategoryEncryptEnabbled;
		this.crossNetType = crossNetType;
	}

	/**
	 * 是否不加密
	 */
	@Override
	public boolean exclude(T obj) {
		//如果关闭了加密开关，则不加密
		if(!KernelParam.encryptStoreEnable){
			return true;
		}
		//当前数据分类配置了加密则加密
		if(!dataCategoryEncryptEnabbled){
			return true;
		}
		//结构化，统一加密
		if(exchDataType==ExchDataType.CM_DATA){
			return false;//加密
		}
		//非结构化
		if(exchDataType==ExchDataType.FILE_DATA){
			long encryptMaxSize =  KernelParam.encryptMaxSize;
			File file = (File)obj;
			//超过规定大小，不加密
			if(encryptMaxSize<file.length()/1024/1024){
				return true;
			}else{
				return false;//加密
			}
		}
		return true;
	}
}
